<template>
  <van-nav-bar title="标题" left-text="返回" left-arrow placeholder :fixed="fixed" @click-left="onBackClick">
    <template #left>
      <slot name="left" />
    </template>
    <template #title>
      <slot />
    </template>
    <template #right>
      <slot name="right" />
    </template>
  </van-nav-bar>
</template>

<script>
import { noop } from '@/utils'
import { NavBar } from 'vant'
export default {
  components: {
    [NavBar.name]: NavBar
  },
  name: 'NavBar',
  props: {
    back: { type: Function, default: noop },
    fixed: { type: Boolean, default: false }
  },
  methods: {
    onBackClick() {
      if (this.back === noop) this.goBack()
      else this.back()
    }
  }
}
</script>

<style lang="less"></style>
